import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_demo/tmac/SkinChangePage.dart';
import 'package:flutter_demo/tmac/util/DataUtil.dart';
import 'package:flutter_demo/tmac/util/SystemUtil.dart';
import 'package:flutter_demo/tmac/widget/AllDrawableTextWidget2.dart';
import 'package:flutter_demo/tmac/widget/WidgetListItem.dart';
import 'package:flutter_demo/tmac/widgetpage/Container.dart';
import 'package:flutter_demo/tmac/widgetpage/Text.dart';
import 'package:flutter_demo/tmac/widgetpage/WebViewPage.dart';

class WidgetStatefulPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new WidgetState();
  }
}

class WidgetState extends State<WidgetStatefulPage>
    with AutomaticKeepAliveClientMixin {
  List<Widget> widgetList = [];

  @override
  bool get wantKeepAlive => true;

  void fillData() {
    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("文本", style: TextStyle(color: Colors.blue)),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.textUrl(), title: "文本");
          }));
        },
        iconTop: Icon(
          Icons.text_fields,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );
    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("按钮", style: TextStyle(color: Colors.blue)),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.buttonUrl(), title: "按钮");
          }));
        },
        iconTop: Icon(
          Icons.radio_button_checked,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );
    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("图片和Icon", style: TextStyle(color: Colors.blue)),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.imageIconUrl(), title: "图片和Icon");
          }));
        },
        iconTop: Icon(
          Icons.image,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );
    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("复选框&单选框",style: TextStyle(color: Colors.blue),),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.checkboxAndSwitchUrl(), title: "复选框&单选框");
          }));
        },
        iconTop: Icon(
          Icons.check_box,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );

    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("TextFiled",style: TextStyle(color: Colors.blue),),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.textFiledUrl(), title: "TextFiled");
          }));
        },
        iconTop: Icon(
          Icons.input,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );
    widgetList.add(
      AllDrawableTextWidget2(
        title: Text("进度条",style: TextStyle(color: Colors.blue),),
        paddingTop: 7,
        callback: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return WebViewPage(url: DataUtil.instance.progressUrl(), title: "进度条");
          }));
        },
        iconTop: Icon(
          Icons.autorenew,
          color: Colors.blue,
          size: 25,
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    SystemUtil.statusColorBar(color: Colors.blue[800]);
    fillData();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        body: SafeArea(
            child: Container(
      width: double.infinity,//强制撑满宽高
      height: double.infinity,
      color: Colors.grey[100],
      child: Column(
        children: <Widget>[
          Container(
            height: 60,
            color: Colors.blue,
            padding: EdgeInsets.all(10),
            child: TextField(
              maxLines: 1,
              decoration: InputDecoration(
                border: OutlineInputBorder(
                    borderSide: BorderSide.none,
                    borderRadius: BorderRadius.circular(5)),
                prefixIcon: Icon(Icons.search),
                hintText: "请搜索组件",
                fillColor: Colors.white,
                filled: true,
                contentPadding: EdgeInsets.only(
                  left: 10,
                  right: 10,
                ),
              ),
            ),
          ),
          Padding(padding: EdgeInsets.only(top: 10)),
          Expanded(
              child: ListView(
            children: <Widget>[
              WidgetListItem(
                  icon: Icon(
                    Icons.widgets,
                    color: Colors.blue,
                  ),
                  title: Text(
                    "基础控件",
                    style: TextStyle(color: Colors.blue, fontSize: 14),
                  ),
                  centerContent: GridView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: widgetList.length,
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                          childAspectRatio: 1.5, crossAxisCount: 3),
                      itemBuilder: (context, index) {
                        print("index $index");
                        return widgetList[index];
                      })),
            ],
          ))
        ],
      ),
    )));
  }
}
